package com.ebao.action.user;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import com.ebao.action.base.BaseAction;
import com.ebao.constants.UserType;
import com.ebao.po.user.TUserRegister;
import com.ebao.service.user.IUserRegisterService;

/**
 * @author snow
 * @date 2012-7-17
 */
public class UserRegisterAction extends BaseAction {

	private static final long serialVersionUID = -6799977600580837827L;

	@Resource
	private IUserRegisterService userRegisterService;
	
	private String username;	// 用户名
	private String email;		// 邮箱
	private String info;		// 简介
	
	/**
	 * 用户申请注册
	 */
	@Action(value = "user-register", results = {@Result(name = SUCCESS, location = "/index.jsp")})
	public String userRegister(){
		TUserRegister UserRegister = new TUserRegister();
		UserRegister.setUserName(username);
		UserRegister.setEmail(email);
		UserRegister.setIntroduction(info);
		UserRegister.setRegisterDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		UserRegister.setUserType(UserType.COMMON_USER);
		userRegisterService.save(UserRegister);
		return SUCCESS;
	}

	/**
	 * 医生申请注册
	 */
	@Action(value = "doctor-register", results = {@Result(name = SUCCESS, location = "/index.jsp")})
	public String doctorRegister(){
		TUserRegister doctorRegister = new TUserRegister();
		doctorRegister.setUserName(username);
		doctorRegister.setEmail(email);
		doctorRegister.setIntroduction(info);
		doctorRegister.setRegisterDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		doctorRegister.setUserType(UserType.DOCTOR);
		userRegisterService.save(doctorRegister);
		return SUCCESS;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}

}
